<?php

if (!class_exists("PST_SELECTARRAY")) {

    class PST_SELECTARRAY extends PST_PRESENTATION {

        protected $array = array("type" => "select");
        
        public function renderTableMaint() {
            if (isset($this->isvisible) && !$this->isvisible) {
                return '<input type="hidden" name="' . $this->name . '" id="' . $this->id . '" value="' . $this->value . '" />';
            }

            if ($this->readonly) {
                $this->html = false;
                return $this->renderReadOnly();
            }

            $html = '<div id="box' . $this->id . '" class="input select ' . $this->required . '">';
            $html.= '<label for="' . $this->id . '">' . $this->label . '</label>';
            if (isset($this->array["options"]) && is_array($this->array["options"])) {
                $html = '<div id="box' . $this->id . '" class="input select ' . $this->required . '">';
                $html.= '<label for="' . $this->id . '">' . $this->label . '</label>';

                if (isset($this->array["options"])) {
                    $html.= '<select name="' . $this->name . '" id="' . $this->id . '">';
                    $html.= '<option value=""></option>';
                    foreach ($this->array["options"] as $key => $value) {
                        $html.= '<option value="' . $key . '">' . $value . '</option>';
                    }
                    if (!empty($this->initialvalue) && !in_array($this->initialvalue, keys($this->array['options']))) {
                        $html.= '<option value="' . $this->initialvalue . '" selected="selected">' . $this->initialvalue . '</option>';
                    }
                    $html.= '</select>';
                }

                $html.= '</div>';

                return $html;
            }
            $html.= '</div>';
            return $html;
        }
        
        protected function getHelperValue() {
            if (isset($this->array["options"][$this->value])) {
                return $this->array["options"][$this->value];
            }
            return $this->value;
        }
        
        public function objectDBQuery() {
            if (isset($this->field) && isset($this->value)) {                
                return array($this->field => $this->value);
            }
            return array();
        }

    }

}
